package cn.tedu.ems.studyvideo.service.impl;

import cn.tedu.ems.base.response.PageData;
import cn.tedu.ems.studyvideo.dao.mapper.VideoMapper;
import cn.tedu.ems.studyvideo.pojo.dto.VideoDTO;
import cn.tedu.ems.studyvideo.pojo.entity.Video;
import cn.tedu.ems.studyvideo.pojo.query.VideoQuery;
import cn.tedu.ems.studyvideo.pojo.vo.VideoCategory;
import cn.tedu.ems.studyvideo.pojo.vo.VideoVO;
import cn.tedu.ems.studyvideo.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class VideoServiceImpl implements VideoService {
    @Autowired
    VideoMapper videoMapper;

    @Override
    public List<VideoCategory> categorySelect() {
        List<VideoCategory> videoCategories = videoMapper.selectCategory();
        log.debug("videoCategories:{}", videoCategories);
        return videoCategories;
    }

    @Override
    public PageData videoList(VideoQuery videoQuery) {
        List<VideoVO> videoVOS = videoMapper.selectVideo(videoQuery);
        PageData dictData = new PageData();
        dictData.setList(videoVOS);
        dictData.setTotal(videoMapper.selectCount(videoQuery));
        log.debug("这是打印出来的数据:{}", videoVOS);
        return dictData;
    }

    @Override
    public void videoUploadData(VideoDTO videoDTO) {
        Video video = new Video();
        video.setTitle(videoDTO.getTitle());
        video.setCreateTime(new Date());
        video.setArticleVideoCategoryId(video.getArticleVideoCategoryId());
        videoMapper.insertVideo(video);
    }

}
